package udp;

import java.io.IOException;
import java.net.SocketException;
import java.util.HashMap;

//词典服务器
public class UdpDictServer extends UdpEchoServer {
    private HashMap<String, String> hashMap = new HashMap<>();

    public UdpDictServer(int port) throws SocketException {
        super(port);
        hashMap.put("cat", "小猫");
        hashMap.put("dog", "小狗");
        hashMap.put("chicken", "坤坤");
        hashMap.put("aaaaaaaaaa", "测试");
    }

    //start 方法完全从父类中继承下来即可
    //process 方法要进行重写,加入另外的业务逻辑,进行翻译
    @Override
    public String process(String request) {
        return hashMap.getOrDefault(request, "您查的单词不存在!");
    }

    public static void main(String[] args) throws IOException {
        UdpDictServer server = new UdpDictServer(9090);
        server.start();
    }
}
